#include "gy25.h"

uint16_t YPR[3];
uint8_t GY_recvBuff[10];
uint16_t Angle=0;

//uart handle allocated for GY25, which needs to be configured for circular dma with IDLE interrupt on
UART_HandleTypeDef* handle;

void GY_init(UART_HandleTypeDef*huart)
{
	handle=huart;
	__HAL_UART_ENABLE_IT(handle,UART_IT_IDLE);
	HAL_UARTEx_ReceiveToIdle_DMA(handle,GY_recvBuff,8);
}

//put this funciton in HAL_UARTEx_RxEventCallback
void GY_Callback(UART_HandleTypeDef*huart)
{
	if(huart->Instance==handle->Instance)
	{
		if(GY_recvBuff[0]==0xAA && GY_recvBuff[7]==0x55)                
		YPR[0]=(GY_recvBuff[1]<<8|GY_recvBuff[2])/100;
     	Angle = (Angle>180?Angle-300:Angle);
		HAL_UARTEx_ReceiveToIdle_DMA(handle,GY_recvBuff,8);
	}
}
